package com.mayihr.fx.attributeBind.highClassBinding;

import javafx.beans.binding.Binding;
import javafx.beans.binding.Bindings;
import javafx.beans.binding.NumberBinding;
import javafx.beans.property.IntegerProperty;
import javafx.beans.property.SimpleIntegerProperty;

public class Main2 {
    public static void main(String[] args) {
        IntegerProperty num1 = new SimpleIntegerProperty(); //依赖变量
        IntegerProperty num2 = new SimpleIntegerProperty(); //依赖变量
        NumberBinding sum = Bindings.add(num1, num2);       //绑定变量

        num1.addListener((x,y,z)->{
            System.out.println(y);
            System.out.println(z);
            System.out.println("num1 context changed!");
        });

        System.out.println(sum.getValue());
        num1.setValue(2);
        System.out.println(sum.getValue());
    }
}
